<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript">
	$(function() {
		$('#roleAddForm').form({
			url : '${pageContext.request.contextPath}/ebook/fileUpload2',
			onSubmit : function() {
				//progressLoad();
				var isValid = $(this).form('validate');
				if (!isValid) {
					progressClose();
				}
				if (isValid) {
					fSubmit();
				}
				return isValid;
			},
			success : function(result) {
				progressClose();
				result = $.parseJSON(result);
				if (result.success) {
					parent.$.modalDialog.handler.dialog('close');
					parent.$.modalDialog.openner_tree.tree('reload');//之所以能在这里调用到parent.$.modalDialog.openner_dataGrid这个对象，是因为user.jsp页面预定义好了
				} else {
					parent.$.messager.alert('错误', result.msg, 'error');
				}
			}
		});
	});
	function fSubmit() {
		//var button = window.document.getElementById("submitButton");
		var button = $(".l-btn-text:button");
		button.disabled = true;
		//$(".l-btn").remove();
		$(".dialog-button").remove();
		var max = 100;
		var prog = 0;
		var counter = 0;
			document.getElementById('progressBar').style.display = 'block';
			document.getElementById('progressBarText').innerHTML = '上传进度: 0%';
		getProgress();
		doProgressLoop(prog, max, counter);
		//document.getElementById("form1").submit();
	}
	function doProgressLoop(prog, max, counter) {
		var x = null;
			x = document.getElementById('progress-content').innerHTML;
		var y = parseInt(x);
		if (!isNaN(y)) {
			prog = y;
		}
		counter = counter + 1;
		if (prog < 100) {
			setTimeout("getProgress()", 1000);
			setTimeout("doProgressLoop(" + prog + "," + max + "," + counter	+ ")", 1500);
				document.getElementById('progressBarText').innerHTML = '上传进度: '+ prog + '%';
				document.getElementById('progressBarBoxContent').style.width = parseInt(prog)+ '%';
		}
	}

	function getProgress() {
		$.getJSON('${pageContext.request.contextPath}/ebookHelper/ProgressServlet.do','',function(data){
				document.getElementById('progress-content').innerHTML = data;
		});
	}
</script>
<div style="margin: 5px">
	<form id="roleAddForm" action="/lightmvc/ebook/fileUpload2" method="post" enctype="multipart/form-data">
		
		<table cellspacing="0" cellpadding="3" border="1">
			<tbody>
				<tr bgcolor="#398EB7">
					<td colspan="2"><font color="#ffffff">档案上传表格</font></td>
				</tr>
				<tr>
					<td width="150">
						<div align="left">
							<p>
								文件描述： <font face="Verdana"> :&nbsp; </font>
							</p>
						</div>
					</td>
					<td width="324"><font face="Verdana"> <input class="easyui-validatebox" data-options="required:true" type="TEXT" value="" name="description"> <br> </font></td>
				</tr>
				<tr>
					<td>
						<div align="left">
							<p>
								<font face="Verdana">档案:&nbsp;</font> <br>
							</p>
						</div></td>
					<td><font face="Verdana"> <input type="file" name="fileUpload" class="easyui-validatebox" data-options="required:true"/> <br> </font></td>
				</tr>
			</tbody>
		</table>
		<div id="progressBar" style="display: none;">
			<div id="theMeter">
				<div id="progressBarText"></div>
				<div id="progressBarBox" style="color:Silver;border-width:1px;border-style:Solid;width:300px;TEXT-ALIGN:left">
					<div id="progressBarBoxContent" style="background-color:#3366FF; height:15px; width:0%;TEXT-ALIGN:left"></div>
				</div>
				<div id="progress-content" style="display: none;"></div>
			</div>
		</div>
		<div>
			<input type="hidden" value="${sessionInfo.id}" name="loginUserId"> 
			<input type="hidden" value="上传" name="find_ok" /> 
			<input type="hidden" value="清除" name="reset">
			<input type="hidden" name="filePath" value="${myFileUpload.myFilePath}">
			<input type="hidden" name="parentId" value="${myFileUpload.myId}">
		</div>
	</form>
</div>